package com.grow.greenhouse.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grow.greenhouse.common.ErrorCode;
import com.grow.greenhouse.domain.Feedback;
import com.grow.greenhouse.domain.User;
import com.grow.greenhouse.domain.request.FeedbackRequest;
import com.grow.greenhouse.exception.BusinessException;
import com.grow.greenhouse.service.FeedbackService;
import com.grow.greenhouse.mapper.FeedbackMapper;
import com.grow.greenhouse.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
* @author 23854
* @description 针对表【feedback(意见反馈表)】的数据库操作Service实现
* @createDate 2024-01-29 12:34:59
*/
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback>
    implements FeedbackService{


    @Resource
    private UserService userService;

    @Override
    public String sendFeedBack(FeedbackRequest feedbackRequest, HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);
        Long userId = loginUser.getId();
        Feedback feedback = new Feedback();
        feedback.setContent(feedbackRequest.getContent());
        feedback.setUserid(userId);
        boolean save = this.save(feedback);
        if(!save){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"提交反馈失败");
        }
        return "提交反馈成功";
    }
}




